//
//  BonusOperationViewController.m
//  HQJFacilitator
//
//  Created by mymac on 16/9/21.
//  Copyright © 2016年 Fujian first time iot technology investment co., LTD. All rights reserved.
//

#import "BonusOperationViewController.h"
#import "BonusCashViewController.h"
#import "BonusGivingViewController.h"
#import "BonusTransferViewController.h"
#import "SetTableViewCell.h"

@interface BonusOperationViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *BOTableView;
@property (nonatomic,strong)NSArray *titiAry;
@end

@implementation BonusOperationViewController
-(UITableView *)BOTableView {
    if (!_BOTableView) {
        
        
        
        _BOTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 10, WIDTH, HEIGHT) style:UITableViewStylePlain];
        _BOTableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
        _BOTableView.sectionHeaderHeight = 2;
        _BOTableView.sectionFooterHeight = 2;
        _BOTableView.delegate = self;
        _BOTableView.dataSource = self;
        [_BOTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
//        [_BOTableView registerClass:[SetTableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
//        _BOTableView.separatorStyle = UITableViewCellSeparatorStyleNone;

        _BOTableView.tableFooterView = [UIView new];
        
            
        
    }
    
    
    
    return _BOTableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    if ([FileEngine filePathNameReadName:@"is_shopaholic" andstye:filePathlocationStyle]) {
        [self is_shopaholic:[FileEngine filePathNameReadName:@"is_shopaholic" andstye:filePathlocationStyle]];
    } else {
        [self ActionShowRequst];

        
    }
//    self.title =@"积分操作";
    [self.view addSubview:self.BOTableView];
   
    // Do any additional setup after loading the view.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    
    return 1;
}

//-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
//    
//        return 10;
//    
//}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
  
        return _titiAry.count;
     
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class]) forIndexPath:indexPath];
    cell.textLabel.text = _titiAry[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
   
    if (indexPath.row == _titiAry.count-1) {
        
        CellLine(cell);
        
    }
    return cell;
    
    
    
    
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        BonusCashViewController *BCVC = [[BonusCashViewController alloc]init];
        BCVC.title = _titiAry[indexPath.row];
        [self.navigationController pushViewController:BCVC animated:YES];
    } else if (indexPath.row == 1) {
        BonusTransferViewController *BTVC = [[BonusTransferViewController alloc]init];
        BTVC.title = _titiAry[indexPath.row];
        
        [self.navigationController pushViewController:BTVC animated:YES];

   
    }else {
        if (_titiAry.count ==3) {
            BonusGivingViewController *BGVC = [[BonusGivingViewController alloc]init];
            BGVC.title = _titiAry[indexPath.row];
            [self.navigationController pushViewController:BGVC animated:YES];
        }
        
    }
    
    
    
}

-(void)ActionShowRequst {
    NSString *memberidStr = [FileEngine filePathNameReadName:@"memberid" andstye:fileLoginStyle];
    NSString *urlStr = [NSString stringWithFormat:@"%@bonusActionShow/memberid/%@",AppOrg_URL,memberidStr];
    [RequestEngine HQJFacilitatorRequestDetailsUrl:urlStr complete:^(NSDictionary *dic) {
        if ([dic[@"error"] integerValue] == 40098) {
            [ManagerEngine homeSvpStr:@"参数不全" andcenterView:CustomWindow andStyle:promptViewFadeAway];
        }
        if ([dic[@"error"] integerValue] == 0) {
            [self is_shopaholic:dic[@"result"][@"is_shopaholic"]];
            NSMutableDictionary *dic1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:dic[@"result"][@"is_shopaholic"],@"is_shopaholic",nil];
            
            [FileEngine filePathNameCreateandNameMutablefilePatch:filePathlocationStyle Dictionary:dic1];
//            [Manager sharedManager].is_shopaholic = dic[@"result"][@"is_shopaholic"];
        }
        [self.BOTableView reloadData];
    } andError:^(NSError *error) {
        
    } ShowHUD:YES];
    
    
    
}
-(void)is_shopaholic:(NSString *)str {
    if (![str isEqualToString:@"0"]) {
        _titiAry = @[@"积分兑现",
                     @"积分转移",
                     @"积分赠送"];
        
    } else {
        _titiAry = @[@"积分兑现",
                     @"积分转移"];
    }
    
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
